import {
  exportUrl,
  downloadTemplateUrl,
  getTypeCodeList,
} from "@/api/materialStation/mesMaterialStationStorage";

import { exportExcel } from "@/utils/judge";
import excelUpload from "@/components/excel-upload/excelUpload";
import url from "@/axios/url";
import {
  getLineCodeListNew,
  getWorkCellCodeList,
} from "@/api/order/mesProdOrderPlan";
const { messerviceUrl } = url();
let vm = null;
const sendThis = (_this) => {
  vm = _this;
};

export { sendThis };
// 列表头按钮配置
export const operateList = [
  {
    name: $i18n.t("common.export"), //导出
    type: "primary",
    icon: "el-icon-download",
    handleName: "export", //点击时返回的标识
    url: exportUrl,
    //auth: "auth:operlog:export", //权限字段
  },
  // {
  //   name: $i18n.t("common.downloadTemplate"),
  //   type: "success",
  //   icon: "el-icon-download",
  //   handleName: "exportExcel", // 点击时返回的标识
  // },
  // {
  //   // 导入文件
  //   render: (h, scope) => {
  //     // scope列表上选择的数据
  //     const uploadUrl = `${messerviceUrl}mesMaterialStationStorage/importData`;
  //     return (
  //       <excelUpload
  //         action={uploadUrl}
  //         on={{
  //           handleUploadError: (err) => {
  //             // 失败的回调
  //             console.log(err);
  //             vm.refresh();
  //           },
  //           handleUploadSuccess: (res) => {
  //             // 成功 的回调
  //             console.log(res);
  //             vm.refresh();
  //           },
  //         }}
  //       />
  //     );
  //   },
  // },
  // {
  //   name: "新增",
  //   type: "primary",
  //   icon: "el-icon-circle-plus-outline",
  //   handleName: "add", //点击时返回的标识
  // },
  // {
  //   name: "删除",
  //   type: "danger",
  //   icon: "el-icon-delete",
  //   handleName: "deleteBatch", //点击时返回的标识
  //   isMultiple: true, // isSingle 表示必须选择一项//isMultiple: true, // 表示必须多选
  // },
  // {
  //   name: "导入",
  //   type: "primary",
  //   icon: "el-icon-circle-plus-outline",
  //   handleName: "import", //点击时返回的标识
  // },
];
// 行末按钮配置
export const rowConfig = [
  // {
  //   name: "修改",
  //   type: "primary",
  //   class: "row-btn-primary",
  //   handleName: "edit", //点击时返回的标识
  // },
  {
    name: $i18n.t("common.details"), //"详情",
    type: "info",
    class: "row-btn-info",
    handleName: "detail", //点击时返回的标识
  },
  // {
  //   name: "删除",
  //   type: "danger",
  //   class: "row-btn-danger",
  //   handleName: "delete", //点击时返回的标识
  // },
];
// 搜索条件配置
export const searchConfig = {
  data() {
    const self = this;
    return {
      searchDialog: {
        inline: true,
        formDesc: {
          workshopCode: {
            label: $i18n.t("mesMaterialStationStorage.workshopName"),
            type: "select",

            prop: {
              value: "modelingCode",
              text: "modelingName",
            },
            options: async (data) => {
              console.log(self.$store);
              const params = {
                modelingCode: self.$store.getters.factoryCode,
                level: 4,
                modelingType: "0",
              };
              const list = await getLineCodeListNew(params);
              this.workshopList = list.data.result;
              return list.data.result;
            },
            on: {
              change() {
                self.searchDialog.lineCode = "";
                self.searchDialog.lineName = "";
                self.searchDialog.workCellCode = "";
                self.searchDialog.workCellName = "";
              },
            },
          },
          lineCode: {
            label: $i18n.t("mesMaterialStationStorage.lineName"),
            type: "select",

            optionsLinkageFields: ["workshopCode"],
            // required: true,
            attrs: {
              filterable: true,
            },

            prop: {
              value: "modelingCode",
              text: "modelingName",
            },
            options: async (data) => {
              self.submitLineList = [];
              if (!data.workshopCode) return [];
              let res = await getWorkCellCodeList({
                modelingCode: data.workshopCode,
              });
              let { result } = res.data;
              self.submitLineList = result || [];
              return self.submitLineList;
            },
            on: {
              change() {
                self.searchDialog.workCellCode = "";
                self.searchDialog.workCellName = "";
              },
            },
          },
          workCellCode: {
            label: $i18n.t("mesMaterialStationStorage.workCellName"),
            type: "select",

            optionsLinkageFields: ["lineCode"],
            // required: true,
            attrs: {
              filterable: true,
            },

            prop: {
              value: "modelingCode",
              text: "modelingName",
            },
            options: async (data) => {
              self.submitLineList = [];
              if (!data.lineCode) return [];
              let res = await getWorkCellCodeList({
                modelingCode: data.lineCode,
              });
              let { result } = res.data;
              self.submitLineList = result || [];
              return self.submitLineList;
            },
          },
          typeCode: {
            type: "select",
            label: $i18n.t("mesMaterialStationStorage.typeCode"),
            prop: {
              value: "typeCode",
              text: "typeName",
            },
            options: async (data) => {
              const list = await getTypeCodeList();
              return list.data.result;
            },
          },
          equipmentCode: {
            type: "input",
            label: $i18n.t("mesMaterialStationStorage.equipmentCode"),
          },
          equipmentName: {
            type: "input",
            label: $i18n.t("mesMaterialStationStorage.equipmentName"),
          },
          stationCode: {
            type: "input",
            label: $i18n.t("mesMaterialStationStorage.stationCode"),
          },
          stationName: {
            type: "input",
            label: $i18n.t("mesMaterialStationStorage.stationName"),
          },
          materialCode: {
            type: "input",
            label: $i18n.t("mesMaterialStationStorage.materialCode"),
          },
          materialName: {
            type: "input",
            label: $i18n.t("mesMaterialStationStorage.materialName"),
          },
        },
      },
    };
  },
};
// 新增/删除表单配置
export const formDescDialog = {
  span: 24,
  disabled: false,
  isShowSubmitBtn: true,
  formDesc: {
    stationCode: {
      type: "input",
      label: $i18n.t("mesMaterialStationStorage.stationCode"),
      layout: 12,
      required: false,
    },
    stationName: {
      type: "input",
      label: $i18n.t("mesMaterialStationStorage.stationCode"),
      layout: 12,
      required: false,
    },
    typeCode: {
      type: "input",
      label: $i18n.t("mesMaterialStationStorage.typeCode"),
      layout: 12,
      required: false,
    },
    // workshopCode: {
    //   type: "input",
    //   label: "车间编号",
    //   layout: 12,
    //   required: false,
    // },
    workshopName: {
      type: "input",
      label: $i18n.t("mesMaterialStationStorage.workshopName"),
      layout: 12,
      required: false,
    },
    // lineCode: {
    //   type: "input",
    //   label: "线体编码",
    //   layout: 12,
    //   required: false,
    // },
    lineName: {
      type: "input",
      label: $i18n.t("mesMaterialStationStorage.lineName"),
      layout: 12,
      required: false,
    },
    // workCellCode: {
    //   type: "input",
    //   label: "工位编码",
    //   layout: 12,
    //   required: false,
    // },
    workCellName: {
      type: "input",
      label: $i18n.t("mesMaterialStationStorage.workCellName"),
      layout: 12,
      required: false,
    },
    equipmentCode: {
      type: "input",
      label: $i18n.t("mesMaterialStationStorage.equipmentCode"),
      layout: 12,
      required: false,
    },
    equipmentName: {
      type: "input",
      label: $i18n.t("mesMaterialStationStorage.equipmentName"),
      layout: 12,
      required: false,
    },
    materialCode: {
      type: "input",
      label: $i18n.t("mesMaterialStationStorage.materialCode"),
      layout: 12,
      required: false,
    },
    materialName: {
      type: "input",
      label: $i18n.t("mesMaterialStationStorage.materialName"),
      layout: 12,
      required: false,
    },
    volume: {
      type: "number",
      label: $i18n.t("mesMaterialStationStorage.volume"),
      layout: 12,
      required: false,
    },
    safetyStock: {
      type: "number",
      label: $i18n.t("mesMaterialStationStorage.safetyStock"),
      layout: 12,
      required: false,
    },
    inventoryQuantity: {
      type: "number",
      label: $i18n.t("mesMaterialStationStorage.inventoryQuantity"),
      layout: 12,
      required: false,
    },
    // availableQuantity: {
    //   type: "number",
    //   label: "可用数量",
    //   layout: 12,
    //   required: false,
    // },
    // frozenQuantity: {
    //   type: "number",
    //   label: "冻结数量",
    //   layout: 12,
    //   required: false,
    // },
    unit: {
      type: "input",
      label: $i18n.t("mesMaterialStationStorage.unit"),
      layout: 12,
      required: false,
    },
    // factoryCode: {
    //   type: "input",
    //   label: "工厂编码",
    //   layout: 12,
    //   required: false,
    // },
    // remark: {
    //   type: "input",
    //   label: "备注",
    //   layout: 12,
    //   required: false,
    // },
  },
};
